<?php
function checkPhone($tel){
    if(strlen($tel)=="11"){
        //上面部分判断长度是不是11位
        $n = preg_match_all("/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/",$tel,$array);
        /*接下来的正则表达式("/131,132,133,135,136,139开头随后跟着任意的8为数字 '|'(或者的意思)
         * 151,152,153,156,158.159开头的跟着任意的8为数字
         * 或者是188开头的再跟着任意的8为数字,匹配其中的任意一组就通过了
         * /")*/
        dump($n);
        dump($array);
        return $array;
         
    }else{
        return 0;
    }
}
function checkPhone2($tel)
{
    $pattern = "/^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8])|(19[7]))\d{8}$/";
    if(!strlen($tel)=='11')
    {
        return 0;
    }else
    {
       preg_match($pattern,$tel,$matches);
       return $matches[0];
    }
}
function ajaxReturn2($status="",$info="",$data=""){
    $result=array();
    $result['status']="0";
    $result['info']="";
    $result['data']=array();
    if(!empty($status)){$result['status'] = $status;}
    if(!empty($info)){$result['info'] = $info;}
    if(!empty($data)){$result['data'] = $data;}
    echo json_encode($result);
    exit();
}
/**
 * 
 * @param unknown $arr
 * @return string|unknown
 * 传递一个数组将里面的中文进行编码
 */
function ch_json($arr){
    if(is_array($arr)){
        foreach ($arr as $key => $value) {
            $arr[urlencode($key)] = ch_json($value);
        }
    }else{
        return urlencode($arr);
    }
    return $arr;
}

/**
 * 
 * @param unknown $arr
 * @return string|unknown
 * 传递一个数组 将中文的进行解码
 */

function ch_arr($arr){
    if(is_array($arr)){
        foreach ($arr as $key=>$value){
            $arr[urldecode($key)]=ch_arr($value);
        }
    }else{
        return urldecode($arr);
    }
    return $arr;
}
  function quotReg($old){
    $new = preg_replace('/&quot;/','"',$old);
    return $new;
}
//异步上传图片
function ajaxUploadImg(){
   $file=request()->file('image');
   $info = $file->validate(['size'=>15678,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
   if($info){
       echo $info->getExtension();
       echo $info->getSaveName();
       echo $info->getFilename();
   }
  
}
function SortPaxu($arr){
   
    //首先定义一个数组；
    //计算数组的长度；
    $length =count($arr);
    //外层循环n-1
    for($n=0;$n<$length-1;$n++){
        //内层循环n-i-1
        for($i=0;$i<$length-$n-1;$i++){
            //判断数组元素大小，交换位置，实现从小往大排序
            if($arr[$i]>$arr[$i+1]){
                $temp=$arr[$i+1];
                $arr[$i+1]=$arr[$i];
                $arr[$i]=$temp;
            }
             
        }
         
    }
   return $arr;
}
function a_array_unique($array)//写的比较好
{
    $out = array();
    foreach ($array as $key=>$value) {
        if (!in_array($value, $out))
        {
            $out[] = $value;
        }
    }
    return $out;
}
//进行重复的排序之后重新相连的拆开
function IsCountinuous($arr,$len){
    $max=-1;
    $min=-1;
    $data=array();
    $data2=array();
    for($i=0;$i<$len;$i++){
        if($arr[$i]!=0){
            if($arr[$i]>$max|| $max==-1){
                $max=$arr[$i];
                //echo $max;
               
            }
            if($arr[$i]<$min || $min==-1){
                $min=$arr[$i];
                //echo $min;
            }
        }
       
        if($max-$min<$len){
          $data[]=$max;
        }else{
           
           $data2[]=$max;
        }
    }
  // $le=count($data);
   //$str=$data[0].":00-".$data[$le-1].":00";
   
  // $le2=count($data2);
   
   //$str2=$data2[0].":00-".$data2[$le2-1].":00";
   
   $new_data=array($data,$data2);
   return $new_data;
    
    
}
function createOrderNum(){
    return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
}
function createOrderNum2(){
    return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
function createOrderNum3(){
    @date_default_timezone_set("PRC");
   
    
        //订购日期
    
        $order_date = date('Y-m-d');
    
        //订单号码主体（YYYYMMDDHHIISSNNNNNNNN）
    
        $order_id_main = date('YmdHis') . rand(10000000,99999999);
    
        //订单号码主体长度
    
        $order_id_len = strlen($order_id_main);
    
        $order_id_sum = 0;
    
        for($i=0; $i<$order_id_len; $i++){
    
            $order_id_sum += (int)(substr($order_id_main,$i,1));
    
        }
        $order_id = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
        return $order_id;

}
function createOrderNum4(){
    $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
    $orderSn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
    return $orderSn;
        
}
function create_sn(){
    mt_srand((double )microtime() * 1000000 );
    return date("YmdHis" ).str_pad( mt_rand( 1, 99999 ), 5, "0", STR_PAD_LEFT );
}
function build_order_no() {
    return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
function guid() {
        mt_srand((double)microtime()*10000);
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);
        $uuid   = chr(123)
        .substr($charid, 0, 8).$hyphen
        .substr($charid, 8, 4).$hyphen
        .substr($charid,12, 4).$hyphen
        .substr($charid,16, 4).$hyphen
        .substr($charid,20,12)
        .chr(125);
        return $uuid;
    
}
function array_to_fe($str){
    $str=str_ireplace(":00","", $str);
    $arr=explode('-', $str);
    $count=$arr[1]-$arr[0];
    return $count;
}
function time_line($time) {
    $rtime = $time;
    $time  = time()-$time;
    $arr=array();
    if ($time < 60) {
        $str = $time."秒前";
        $arr['mi']=$str;
    } elseif ($time < 60*60) {
        $min = floor($time/60);
        
        $arr['min']=$min;
    } elseif ($time < 60*60*24) {
        $h   = floor($time/(60*60));
       $arr['h']=$h;
    } elseif ($time < 60*60*24*3) {
        $d = floor($time/(60*60*24));
        if ($d == 1) {
            $arr['d']=$d;
        } else {

            $str = $d.'天以前';
        }
    } else {
        $str = $rtime;
    }
    return $arr;
}
function time_line2($time) {
  
    $arr=array();
    $hou=floor($time/(60*60));
    
    $mi=floor($time/60);
    
    if($mi>60){
        $mi=$mi-60;
    }
    
    $arr['h']=empty($hou)?0:$hou;
    $arr['m']=empty($mi)?0:$mi;
    $miao=$time-(3600*$hou)-(60*$mi);
    $arr['i']=$miao;
    return $arr;
}
function timediff( $begin_time, $end_time )
{
    if ( $begin_time < $end_time ) {
        $starttime = $begin_time;
        $endtime = $end_time;
    } else {
        $starttime = $end_time;
        $endtime = $begin_time;
    }
    $timediff = $endtime - $starttime;
    $days = intval( $timediff / 86400 );
    $remain = $timediff % 86400;
    $hours = intval( $remain / 3600 );
    $remain = $remain % 3600;
    $mins = intval( $remain / 60 );
    $secs = $remain % 60;
    $res = array( "day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs );
    return $res;
}
//======== 实例使用 ========
function time_line3($time){
    $data=[];
    $rtime = $time;
    $time = time () - $time;

    if($time < 60){
        $str = $time.'秒之前';
        $data['sec']=$time;
    }elseif($time < 60*60){
        $min = floor( $time/60 );
        $str = $min.'分钟前';
        $data['min']=$min;
    }elseif($time < 60*60*24){
        $h = floor($time/(60*60));
        $str = $h.'小时前 ';
        $data['hour']=$h;
    }elseif($time < 60*60*24*3) {
        $d = floor($time/(60*60*24));
        if ($d == 1)
            $str = $d.'天以前';
            else
                $str = $d.'天以前';
    }else{
        $str = $rtime;
    }
    return $data;
}
function time_line4($time) {

    $arr=array();
    $time=time()-$time;
    $hou=floor($time/(60*60));

    $mi=floor($time/60);

    if($mi>60){
        $mi=$mi-60;
    }

    $arr['hour']=empty($hou)?0:$hou;
    $arr['min']=empty($mi)?0:$mi;
    $miao=$time-(3600*$hou)-(60*$mi);
    $arr['sec']=$miao;
    return $arr;
}
function quotReg2($old){
    $new = preg_replace('/&quot;/','"',$old);
    return $new;
}


